package com.example.teesystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.teesystem.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * @author 12510
 * @description 针对表【t_user】的数据库操作Mapper
 * @createDate 2022-03-23 09:49:07
 * @Entity com.example.teesystem.entity.User
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from t_user where is_delete = 0")
    List<User> getAllUser();

    @Select("select * from t_user where account = #{account} and password = #{password}")
    User getMyMessage(String account, String password);

    @Select("select id from t_user where account = #{account} and is_delete = 0")
    int getUidByAccount(String account);

    @Update("update t_user set username = #{username},gender = #{gender},birthday = #{birthday},my_name = #{name},academy = #{academy}," +
            "grade = #{grade},classes = #{classes},mail = #{mail},update_time = #{updateTime} where id = #{uid}")
    void updateMyMessage(String username, String gender, Date birthday, String name, String academy, int grade, int classes, String mail, int uid, Date updateTime);

    @Update("update t_user set password = #{password} where id = #{uid}")
    void updatePassword(String password, int uid);

    @Update("update t_user set account_type = #{accountType} where id = #{id}")
    void updateAccountTypeById(int id, int accountType);

    @Update("update t_user set password = #{password} where id = #{id}")
    void updatePasswordById(int id, String password);

    @Select({
            "<script>"+
            "select * from t_user where id in " +
            "<foreach item = 'item' index = 'index' collection = 'ids' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>"+
            "</script>"
    })
    List<User> getUsersByIds(@Param("ids") List<Integer> ids);

    @Update("update t_user set avatar_url = #{avatarUrl} where id = #{uid} ")
    void updateAvatarUrl(int uid,String avatarUrl);

    @Update("update t_user set count = count + 1 where id = #{id}")
    void loginSuccess(int id);

    @Select("select count from t_user where id = #{uid}")
    int getUserLoginCount(int uid);
}




